import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_SDR } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 查询执行器列表数据
 * @async
 * @function fetchGroupsList
 * @param {object} params - 查询条件
 */

export function fetchGroupsList() {
  return _fetchGroupsList.apply(this, arguments);
}
/**
 * 查询列表数据
 * @async
 * @function fetchPortalAssign
 * @param {Object} params - 查询参数
 * @param {String} [params.page = 0] - 页码
 * @param {String} [params.size = 0] - 页数
 */

function _fetchGroupsList() {
  _fetchGroupsList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/executors/available") : "".concat(CPAAS_SDR, "/v1/executors/available"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchGroupsList.apply(this, arguments);
}

export function fetchJobInfo(_x) {
  return _fetchJobInfo.apply(this, arguments);
}
/**
 * 查询某一个
 * @async
 * @function fetchPortalAssign
 * @param {Object} params - 查询参数
 */

function _fetchJobInfo() {
  _fetchJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info") : "".concat(CPAAS_SDR, "/v1/job-info"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchJobInfo.apply(this, arguments);
}

export function queryJobInfo(_x2) {
  return _queryJobInfo.apply(this, arguments);
}
/**
 * 保存glue
 * @async
 * @function updateJobGlue
 * @param {Object} params - 查询参数
 */

function _queryJobInfo() {
  _queryJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info/").concat(params.id) : "".concat(CPAAS_SDR, "/v1/job-info/").concat(params.id), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _queryJobInfo.apply(this, arguments);
}

export function updateJobGlue(_x3) {
  return _updateJobGlue.apply(this, arguments);
}
/**
 * 查询glue列表
 * @async
 * @function queryJobGlueList
 * @param {Object} params - 查询参数
 */

function _updateJobGlue() {
  _updateJobGlue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/glue-logs") : "".concat(CPAAS_SDR, "/v1/glue-logs"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateJobGlue.apply(this, arguments);
}

export function queryJobGlueList(_x4) {
  return _queryJobGlueList.apply(this, arguments);
}
/**
 * 查询某个glue
 * @async
 * @function queryJobGlueDetail
 * @param {Object} params - 查询参数
 */

function _queryJobGlueList() {
  _queryJobGlueList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/glue-logs") : "".concat(CPAAS_SDR, "/v1/glue-logs"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryJobGlueList.apply(this, arguments);
}

export function queryJobGlueDetail(_x5) {
  return _queryJobGlueDetail.apply(this, arguments);
}
/**
 * 创建
 * @async
 * @function createJobInfo
 * @param {String} params.enabledFlag - 是否启用
 * @param {String} params.groupNum - 集团编码
 */

function _queryJobGlueDetail() {
  _queryJobGlueDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/glue-logs/").concat(params.id) : "".concat(CPAAS_SDR, "/v1/glue-logs/").concat(params.id), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _queryJobGlueDetail.apply(this, arguments);
}

export function createJobInfo(_x6) {
  return _createJobInfo.apply(this, arguments);
}
/**
 * 修改
 * @async
 * @function updateJobInfo
 * @param {String} params.enabledFlag - 是否启用
 */

function _createJobInfo() {
  _createJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info") : "".concat(CPAAS_SDR, "/v1/job-info"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _createJobInfo.apply(this, arguments);
}

export function updateJobInfo(_x7) {
  return _updateJobInfo.apply(this, arguments);
}
/**
 * 删除
 * @async
 * @function updateJobInfo
 * @param {String} params.enabledFlag - 是否启用
 */

function _updateJobInfo() {
  _updateJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info") : "".concat(CPAAS_SDR, "/v1/job-info"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _updateJobInfo.apply(this, arguments);
}

export function deleteJobInfo(_x8) {
  return _deleteJobInfo.apply(this, arguments);
}
/**
 * 暂停
 * @async
 * @function updateJobInfo
 * @param {String} params.enabledFlag - 是否启用
 */

function _deleteJobInfo() {
  _deleteJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info") : "".concat(CPAAS_SDR, "/v1/job-info"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _deleteJobInfo.apply(this, arguments);
}

export function pauseJobInfo(_x9) {
  return _pauseJobInfo.apply(this, arguments);
}
/**
 * 恢复
 * @async
 * @function updateJobInfo
 * @param {String} params.enabledFlag - 是否启用
 */

function _pauseJobInfo() {
  _pauseJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    var jobId, tenantId;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            jobId = params.jobId, tenantId = params.tenantId;
            return _context10.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info/pause") : "".concat(CPAAS_SDR, "/v1/job-info/pause"), {
              method: 'POST',
              body: {
                jobId: jobId,
                tenantId: tenantId
              }
            }));

          case 2:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _pauseJobInfo.apply(this, arguments);
}

export function resumeJobInfo(_x10) {
  return _resumeJobInfo.apply(this, arguments);
}
/**
 * 执行
 * @async
 * @function updateJobInfo
 * @param {String} params.enabledFlag - 是否启用
 */

function _resumeJobInfo() {
  _resumeJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    var jobId, tenantId;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            jobId = params.jobId, tenantId = params.tenantId;
            return _context11.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info/resume") : "".concat(CPAAS_SDR, "/v1/job-info/resume"), {
              method: 'POST',
              body: {
                jobId: jobId,
                tenantId: tenantId
              }
            }));

          case 2:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _resumeJobInfo.apply(this, arguments);
}

export function triggerJobInfo(_x11) {
  return _triggerJobInfo.apply(this, arguments);
}
/**
 * 终止
 * @async
 * @function stopJob
 * @param {String} params.enabledFlag - 是否启用
 */

function _triggerJobInfo() {
  _triggerJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(params) {
    var jobId, tenantId;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            jobId = params.jobId, tenantId = params.tenantId;
            return _context12.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info/trigger") : "".concat(CPAAS_SDR, "/v1/job-info/trigger"), {
              method: 'POST',
              body: {
                jobId: jobId,
                tenantId: tenantId
              }
            }));

          case 2:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _triggerJobInfo.apply(this, arguments);
}

export function stopJob(_x12) {
  return _stopJob.apply(this, arguments);
}

function _stopJob() {
  _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(params) {
    var jobId, tenantId;
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            jobId = params.jobId, tenantId = params.tenantId;
            return _context13.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info/stop") : "".concat(CPAAS_SDR, "/v1/job-info/stop"), {
              method: 'POST',
              body: {
                jobId: jobId,
                tenantId: tenantId
              }
            }));

          case 2:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _stopJob.apply(this, arguments);
}

export function fetchJobLog(_x13) {
  return _fetchJobLog.apply(this, arguments);
}
/**
 * 查询错误日志详情
 * @async
 * @function fetchJobLogError
 * @param {Object} params - 查询参数
 */

function _fetchJobLog() {
  _fetchJobLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(params) {
    var jobId, param;
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            jobId = params.jobId;
            param = parseParameters(params);
            return _context14.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs/").concat(jobId, "/logs") : "".concat(CPAAS_SDR, "/v1/job-logs/").concat(jobId, "/logs"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _fetchJobLog.apply(this, arguments);
}

export function fetchJobLogError(_x14) {
  return _fetchJobLogError.apply(this, arguments);
}
/**
 * 删除
 * @async
 * @function deleteJobLog
 * @param {String} params.enabledFlag - 是否启用
 */

function _fetchJobLogError() {
  _fetchJobLogError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(params) {
    return _regeneratorRuntime.wrap(function _callee15$(_context15) {
      while (1) {
        switch (_context15.prev = _context15.next) {
          case 0:
            return _context15.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs/").concat(params.logId, "/error-detail") : "".concat(CPAAS_SDR, "/v1/job-logs/").concat(params.logId, "/error-detail"), {
              method: 'GET',
              responseType: 'text'
            }));

          case 1:
          case "end":
            return _context15.stop();
        }
      }
    }, _callee15);
  }));
  return _fetchJobLogError.apply(this, arguments);
}

export function deleteJobLog(_x15) {
  return _deleteJobLog.apply(this, arguments);
}
/**
 * 获取任务进度
 * @async
 * @function fetchProgress
 * @param {Object} params - 查询参数
 */

function _deleteJobLog() {
  _deleteJobLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(params) {
    return _regeneratorRuntime.wrap(function _callee16$(_context16) {
      while (1) {
        switch (_context16.prev = _context16.next) {
          case 0:
            return _context16.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs") : "".concat(CPAAS_SDR, "/v1/job-logs"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context16.stop();
        }
      }
    }, _callee16);
  }));
  return _deleteJobLog.apply(this, arguments);
}

export function fetchProgress(_x16) {
  return _fetchProgress.apply(this, arguments);
}
/**
 * 复制任务
 * @async
 * @function copyJobInfo
 * @param {Object} params - 查询参数
 */

function _fetchProgress() {
  _fetchProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(params) {
    return _regeneratorRuntime.wrap(function _callee17$(_context17) {
      while (1) {
        switch (_context17.prev = _context17.next) {
          case 0:
            return _context17.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-logs/").concat(params.logId, "/progress") : "".concat(CPAAS_SDR, "/v1/job-logs/").concat(params.logId, "/progress"), {
              method: 'GET',
              responseType: 'text'
            }));

          case 1:
          case "end":
            return _context17.stop();
        }
      }
    }, _callee17);
  }));
  return _fetchProgress.apply(this, arguments);
}

export function copyJobInfo(_x17) {
  return _copyJobInfo.apply(this, arguments);
}

function _copyJobInfo() {
  _copyJobInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(params) {
    return _regeneratorRuntime.wrap(function _callee18$(_context18) {
      while (1) {
        switch (_context18.prev = _context18.next) {
          case 0:
            return _context18.abrupt("return", request(organizationRoleLevel ? "".concat(CPAAS_SDR, "/v1/").concat(organizationId, "/job-info/").concat(params.jobId, "/copy") : "".concat(CPAAS_SDR, "/v1/job-info/").concat(params.jobId, "/copy"), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context18.stop();
        }
      }
    }, _callee18);
  }));
  return _copyJobInfo.apply(this, arguments);
}